import { Action, combineReducer, createStore } from "./redux";

let initState = {
    counter: {
        count: 1,
    },
    info: {
        name: "luyi",
        age: 36,
    }
}
export type ReduxState = typeof initState;
const counterReducer = (state: ReduxState['counter'], action: Action) => {
    switch (action.type) {
        case "ADD_COUNT":
            return { count: state.count + 1 }
        case "MINUS_COUNT":
            return { count: state.count - 1 }
        default:
            return state;
    }
}

const infoReducer = (state: ReduxState['info'], action: Action) => {
    switch (action.type) {
        case "ADD_AGE":
            return { ...state, age: state.age + 1 }
        case "MINUS_AGE":
            return { ...state, age: state.age + 1 }
        default:
            return state;
    }
}



const reducer = combineReducer({
    counter: counterReducer,
    info: infoReducer
});

export const store = createStore(reducer, initState)